Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing /
Chapter 2 - Core Printing Features / Using Core Printing Features


Supporting Printing From the Finder

A user can print from the Finder in two ways. A user can select a document and then choose the Print menu command from the File menu, or the user can drag a document to a desktop printer icon. To support printing from the Finder, your application must respond to the Print Documents ('pdoc') Apple event. Apple events provide your application with a standard mechanism for communicating with other applications.

To handle the Print Documents event, your application should print the documents specified in the Apple event. You can determine whether a document was dragged to a desktop printer icon by checking the keyOptionalKeywordAttr attribute of the Print Documents Apple event. Your application extracts this information and then prints the specified documents. Your application should not open any windows for the documents. The Print Documents Apple event is discussed in the Apple events chapter of Inside Macintosh: Interapplication Communication.

Your application is responsible for determining the output printer on which to print the document. When a user drags a document to a desktop printer icon, your application must call the GXSelectJobOutputPrinter function to specify the output printer on which to print the selected document. This call is necessary because the document may have been printed previously and that job information may have been saved with the document. The GXSelectJobOutputPrinter function allows you to reselect the printer.

Listing 2-16 shows how to respond to the Print Documents Apple event and specify an output printer.

Listing 2-16 Responding to the Print Documents Apple event and specifying an output printer

pascal OSErr MyHandlePDOC(AppleEvent *theAppleEvent, 
                           AppleEvent *reply, long myRefCon)
{
   OSErr          err;
   AEDescList     docList, dtpList;
   FSSpec         myFSS, dtpFSS;
   long           itemsInList, i;
   AEKeyword      theKeyword;
   DescType       typeCode;
   Boolean        draggedToDTP = false;
   Size           actualSize;
   MyDocumentRec  myDocument;

/* Get the document list. */
   err = AEGetParamDesc(theAppleEvent, keyDirectObject, 
                        typeAEList, &docList);
   if (err) return err;

/* 
   Check to see if the user dragged the document to a desktop 
   printer.
*/
   err = AEGetParamDesc(theAppleEvent, keyOptionalKeywordAttr, 
                        typeAEList, &dtpList);
   if (err == noErr) draggedToDTP = true;

/* 
   Make sure you've accounted for all of the parameters passed 
   and count the number of documents specified.
*/
   err = MyCheckAEParams(theAppleEvent);
   if (err) return err;
   err = AECountItems(&docList, &itemsInList);
   if (err) return err;

/* 
   If the user dragged the document to a desktop printer, get the 
   name of the desktop printer and throw away its description 
   list.
*/
   if (draggedToDTP)
   {
      err = AEGetNthPtr(&dtpList, 1, typeFSS, &theKeyword, 
                        &typeCode, (Ptr) &dtpFSS, 
                        sizeof(FSSpec), &actualSize);
      AEDisposeDesc(&dtpList);
   }

   /* 
      For each entry in the document list, load it, print it, and 
      close it.
   */
   for (i = 1; i<= itemsInList, err == noErr; i++)
   {
      err = AEGetNthPtr(&docList, i, typeFSS, &theKeyword, 
                        &typeCode, (Ptr) &myFSS, sizeof(FSSpec), 
                        &actualSize);

      if (err == noErr)
      {
         /* Load the document. */
         err = MyNewDocument("\p", &myDocument);
         if (err == noErr)
         {
            err = MyFSOpenDocument(&myDocument, &myFSS);
            if (err == noErr)

            /*
               If the user dragged the document to a desktop
               printer, select this printer as the output printer
               for each job object.
            */
            {
               if (draggedToDTP)
                  GXSelectJobOutputPrinter(myDocument.documentJob, 
                                             dtpFSS.name);
               err = MyPrintDocument(&myDocument);
            }

            /* Close the document once it's printed. */
            MyCloseDocument(&myDocument);
         }
      }
   }

/* When you're done, throw away the document list. */
   AEDisposeDesc(&docList);
   return err;
}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help